/**
 * 
 */
package com.dalonedrow.engine.sprite.base;

/**
 * @author DaLoneDrow
 */
public final class SimpleDimension {
	/** The height dimension; negative values can be used. */
	public int height;
	/** The width dimension; negative values can be used. */
	public int width;
	/**
	 * Creates an instance of <code>SimpleDimension</code> with a width of zero
	 * and a height of zero.
	 */
	public SimpleDimension() {
		this(0, 0);
	}
	/**
	 * Constructs a <code>SimpleDimension</code> and initializes it to the
	 * specified width and specified height.
	 * @param w the specified width
	 * @param h the specified height
	 */
	public SimpleDimension(final int w, final int h) {
		this.width = w;
		this.height = h;
	}
	/**
	 * Creates an instance of <code>SimpleDimension</code> whose width and
	 * height are the same as for the specified SimpleDimension.
	 * @param d the specified SimpleDimension for the <code>width</code> and
	 *        <code>height</code> values
	 */
	public SimpleDimension(final SimpleDimension d) {
		this(d.width, d.height);
	}
	/**
	 * Checks whether two <code>SimpleDimension</code> objects have equal 
	 * values.
	 * @param obj the {@link Object} being compared
	 * @return true if the <code>SimpleDimension</code> objects have equal 
	 * values; false otherwise
	 */
	public boolean equals(final Object obj) {
		if (obj instanceof SimpleDimension) {
			SimpleDimension d = (SimpleDimension) obj;
			return width == d.width && height == d.height;
		}
		return false;
	}
	/**
	 * {@inheritDoc}
	 * @since 1.2
	 */
	public double getHeight() {
		return height;
	}
	/**
	 * Gets the size of this <code>SimpleDimension</code> object. This method is
	 * included for completeness, to parallel the <code>getSize</code> method
	 * defined by <code>Component</code>.
	 * @return the size of this SimpleDimension, a new instance of
	 *         <code>SimpleDimension</code> with the same width and height
	 * @see java.awt.SimpleDimension#setSize
	 * @see java.awt.Component#getSize
	 * @since 1.1
	 */
	public SimpleDimension getSize() {
		return new SimpleDimension(width, height);
	}
	/**
	 * {@inheritDoc}
	 * @since 1.2
	 */
	public double getWidth() {
		return width;
	}
	/**
	 * Returns the hash code for this <code>SimpleDimension</code>.
	 * @return a hash code for this <code>SimpleDimension</code>
	 */
	@Override
	public int hashCode() {
		int sum = width + height;
		return sum * (sum + 1) / 2 + width;
	}
	/**
	 * Sets the size of this <code>SimpleDimension</code> object to the
	 * specified width and height in double precision. Note that if
	 * <code>width</code> or <code>height</code> are larger than
	 * <code>Integer.MAX_VALUE</code>, they will be reset to
	 * <code>Integer.MAX_VALUE</code>.
	 * @param w the new width for the <code>SimpleDimension</code> object
	 * @param h the new height for the <code>SimpleDimension</code> object
	 * @since 1.2
	 */
	public void setSize(final double w, final double h) {
		width = (int) Math.ceil(w);
		height = (int) Math.ceil(h);
	}
	/**
	 * Sets the size of this <code>SimpleDimension</code> object to the
	 * specified width and height. This method is included for completeness, to
	 * parallel the <code>setSize</code> method defined by
	 * <code>Component</code>.
	 * @param w the new width for this <code>SimpleDimension</code> object
	 * @param h the new height for this <code>SimpleDimension</code> object
	 * @see java.awt.SimpleDimension#getSize
	 * @see java.awt.Component#setSize
	 * @since 1.1
	 */
	public void setSize(final int w, final int h) {
		width = w;
		height = h;
	}
	/**
	 * Sets the size of this <code>SimpleDimension</code> object to the
	 * specified size. This method is included for completeness, to parallel the
	 * <code>setSize</code> method defined by <code>Component</code>.
	 * @param d the new size for this <code>SimpleDimension</code> object
	 * @see java.awt.SimpleDimension#getSize
	 * @see java.awt.Component#setSize
	 * @since 1.1
	 */
	public void setSize(final SimpleDimension d) {
		setSize(d.width, d.height);
	}
	/**
	 * Returns a string representation of the values of this
	 * <code>SimpleDimension</code> object's <code>height</code> and
	 * <code>width</code> fields. This method is intended to be used only for
	 * debugging purposes, and the content and format of the returned string may
	 * vary between implementations. The returned string may be empty but may
	 * not be <code>null</code>.
	 * @return a string representation of this <code>SimpleDimension</code>
	 *         object
	 */
	@Override
	public String toString() {
		return getClass().getName() + "[width=" + width + ",height=" + height
				+ "]";
	}
}
